home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 131 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.5 KB  |  100 lines

  1. Path: ix.netcom.com!netnews
  2. From: tjensen@ix.netcom.com (Ted Jensen)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What's so different about 2-D arrays???
  5. Date: Tue, 02 Jan 1996 18:28:49 GMT
  6. Organization: Netcom
  7. Message-ID: <4cbtg9$6o0@ixnews8.ix.netcom.com>
  8. References: <820451938.20697@fredblog.demon.co.uk>
  9. Reply-To: tjensen@ix.netcom.com
  10. NNTP-Posting-Host: pax-ca14-11.ix.netcom.com
  11. X-NETCOM-Date: Tue Jan 02 10:28:25 AM PST 1996
  12. X-Newsreader: Forte Free Agent 1.0.82
  13.  
  14. mark@fredblog.demon.co.uk (Mark Winfield) wrote:
  15.  
  16. >I have been teaching myself 'C' over the last month.  Just before Xmas
  17. >I thought that I had it worked out and that all I had to do was
  18. >practice.  I decided to write a program that would record chess games,
  19. >it would allow move branching as well.  I decided upon this because it
  20. >should use everything I have learnt except DOS calls.
  21. >Now for the problem,
  22.  
  23. >//My own chess recorder program
  24.  
  25. >#include <stdio.h>
  26. >#include <ctype.h>
  27.  
  28. >/*Prototypes*/
  29. >void setup(char pos[8][8]);   
  30.  
  31.  
  32. >void main()
  33. >{
  34. >char pos[8][8];
  35.  
  36. >    setup(pos);
  37.  
  38.  
  39. >    printf("\nWell Done!!");
  40. >}
  41.  
  42. >void setup(char pos[8][8])
  43. >{
  44. >int x,y;    
  45.  
  46. >    pos[1][8]=pos[8][8]='r';
  47. >    pos[2][8]=pos[7][8]='n';
  48. >    pos[3][8]=pos[6][8]='b';
  49.  
  50. >    pos[1][1]=pos[8][1]='R';
  51. >    pos[2][1]=pos[7][1]='N';
  52. >    pos[3][1]=pos[6][1]='B';
  53.  
  54. >    for(x=1;x<9;x++){
  55. >        pos[x][7]='a';
  56. >        pos[x][2]='A';
  57.  
  58. >        for(y=3;y<7;y++)
  59. >            pos[x][y]=' ';
  60. >    }
  61.  
  62. >    pos[4][8]='q';
  63. >    pos[5][8]='k';
  64.  
  65. >    pos[4][1]='Q';
  66. >    pos[5][1]='K';
  67. >}
  68.  
  69. >This program does not work with a '.c' or '.cpp' extension.  If I run
  70. >the program from dos I get well done and then something about NULL
  71. >pointers and the program hangs, so I have to reset. And if I run the
  72. >program from within the TURBO C++ enviroment the program hangs after
  73. >printing well done.
  74.  
  75. >I have written a similar program since, as a test, which uses a 1-D
  76. >array with no problems.  Can someone help me with this problem.
  77.  
  78. Your basic problem here is that you are forgetting that when you
  79. dimension an array with size 8, the range of index values runs from 
  80. zero to 7 instead of 1 to 8.
  81.  
  82. You might want to grab a copy of a tutorial I wrote (ptrtut01.zip) for
  83. beginners on pointers and arrays which should clear up any other
  84. problems you may have here.  It is available at either of the
  85. following sites:
  86.  
  87. http://oak.oakland.edu:8080/SimTel/msdos/c/ptrtut01.zip
  88.  
  89. ftp.coast.net/SimTel/msdos/c/ptrtut01.zip
  90.  
  91. or any of SimTel mirror sites.
  92.  
  93.  
  94.  
  95.  
  96. Ted Jensen                 Author of PTRTUT01.ZIP
  97. Redwood City, CA      A tutorial on C pointers and Arrays
  98. tjensen@ix.netcom.com    Available via Simtel/msdos/c
  99.  
  100.